from flask import *
import requests,base64,json
import config
app = Flask(__name__)
URL = "https://fofa.info/api/v1/info/my?email="+config.config["email"]+"&key="+config.config["key"]
@app.route("/test/<string:name>",methods=["GET"])
def index(name):
    if request.method == "GET":
        ip = str(name)
        re = requests.get(
            URL)
        #print(re.content)
        #ip = "39.156.66.10"
        bip = str(base64.b64encode(ip.encode("utf-8")), "utf-8")
        #print(bip)
        re2 = requests.get(
            "https://fofa.info/api/v1/search/all?email="+config.config["email"]+"&key="+config.config["key"]+"&qbase64=" + str(
                bip))
        #print(re2.text)
        jre2 = json.loads(re2.text)
        i = 0  # i是下标
        c = []
        b = {"results": c}
        while i < len(jre2["results"]):
            # print(jre2["results"][i][2])
            domain = jre2["results"][i][0]
            i += 1
            c.append(domain)
            #print(port)
        #print(b)

        return jsonify(urls=b["results"])



if __name__ == '__main__':
    app.run("192.168.2.128",80)